import { request } from '../../../../services/request';

// 获取保养任务详情
export const getDeviceMaintainDetailApi = async (planId: string) => {
    const requestBody = {
        plan_id: planId
    };

    // 保养任务详情请求
    console.log('保养任务详情请求数据:', requestBody);

    try {
        const response = await request('/app/appDeviceInfo/getDeviceMaintainItem', {
            method: 'POST',
            body: JSON.stringify(requestBody)
        });

        // 保养任务详情返回
        console.log('保养任务详情返回:', response);
        return response;
    } catch (error) {
        console.error('获取保养任务详情失败:', error);
        throw error;
    }
};

// 执行保养任务
export const execDeviceMaintainApi = async (data: any) => {
    // console.log('执行保养任务 - 请求数据:', data);

    try {
        const response = await request('/app/appDeviceInfo/execDeviceMaintain', {
            method: 'POST',
            body: JSON.stringify(data)
        });

        // console.log('执行保养任务 - 接口返回:', response);
        return response;
    } catch (error) {
        console.error('执行保养任务失败:', error);
        throw error;
    }
};

// 获取备品备件列表
export const getMaterialListPageApi = async (data: any) => {
    console.log('备品备件接口请求参数:', data);

    try {
        const response = await request('/app/appDeviceInfo/getMaterialListPage', {
            method: 'POST',
            body: JSON.stringify(data)
        });

        console.log('备品备件接口返回数据:', response);
        return response;
    } catch (error) {
        console.error('获取备品备件列表失败:', error);
        throw error;
    }
};

// 获取保养任务复核详情
export const getDeviceMaintainRecordApi = async (deviceId: string, planId: string, cycleId: string) => {
    const requestBody = {
        device_id: deviceId,
        plan_id: planId,
        cycle_id: cycleId
    };
    try {
        const response = await request('/app/appDeviceInfo/getDeviceMaintainRecord', {
            method: 'POST',
            body: JSON.stringify(requestBody)
        });
        console.log('保养任务复核详情返回:', response);
        return response;
    } catch (error) {
        console.error('获取保养任务复核详情失败:', error);
        throw error;
    }
};

// 提交保养复核
export const confirmMaintainPlanApi = async (planId: string, confirmRemark: string) => {
    const requestBody = {
        plan_id: planId,
        confirm_remark: confirmRemark
    };
    try {
        const response = await request('/app/appDeviceInfo/confirmMaintainPlan', {
            method: 'POST',
            body: JSON.stringify(requestBody)
        });
        return response;
    } catch (error) {
        console.error('提交保养复核失败:', error);
        throw error;
    }
}; 